#include"process.h"
#include<string.h>
#define SIZE 101
#define STYLE '#'



//这是进度条的第一个版本，仅仅展示进度条的基本功能，之后会展示进化功能的
void process()
{
  int rate = 0;
  char buffer[SIZE];
  memset(buffer,0,sizeof(buffer));
  const char *lable = "|-/\\";
  int len = strlen(lable);
  while(rate<=100)
  {
    printf("[%-100s][%d%%][%c]\r",buffer,rate,lable[rate % len]);
    fflush(stdout);
    buffer[rate] = STYLE;
    rate++;
    usleep(10000);
  }
  printf("\n");
}


//这是可以动态刷新一次的进度条

void FlushProcess(double total,double current)
{
  char buffer[SIZE];
  memset(buffer,0,sizeof(buffer));
  static int m = 0;
  const char *lable = "|/-\\";
  int len = strlen(lable);
  int i = 0;
  double rate = current * 100 / total;
  int num = (int)rate;
  for(; i < num ;i++)
  {
    buffer[i] = STYLE;
  }
  printf("[%-100s][%.1lf%%][%c]\r",buffer,rate,lable[m]);
  fflush(stdout);
  m++;
  m = m % len;
  if(num >= 100)printf("\n");
}
